<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>实时摄像头视频流</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            margin-bottom: 20px;
        }
        .video-container {
            margin: 20px 0;
            border: 2px solid #ddd;
            border-radius: 4px;
            overflow: hidden;
        }
        img {
            max-width: 100%;
            height: auto;
        }
        .info {
            text-align: left;
            margin-top: 20px;
            padding: 10px;
            background-color: #f9f9f9;
            border-radius: 4px;
            font-size: 14px;
            color: #666;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>实时摄像头视频流</h1>
    <div class="video-container">
        <!-- 使用img标签显示MJPEG流 -->
        <img th:src="@{/video/stream}" alt="实时摄像头视频流" id="videoStream"/>
    </div>
    <div class="info">
        <p><strong>注意事项：</strong></p>
        <ul>
            <li>视频流采用MJPEG技术实现，帧率约为20fps</li>
            <li>关闭页面或刷新页面将自动停止当前视频流</li>
        </ul>
    </div>
</div>

<script>
    // 视频流加载失败时的处理
    document.getElementById('videoStream').onerror = function() {
        console.error('视频流加载失败，尝试重新连接...');
        setTimeout(() => {
            // 使用相对路径或者考虑应用上下文
            this.src = './video/stream?reload=' + new Date().getTime();
        }, 1000);
    };
</script>
</body>
</html>